﻿@{
    Layout = null;
    DeliveryManage.Models.ReturnMsgModel returnMsg = ViewBag.ReturnMsgModel;
}
@model DeliveryManage.Model.Pro_ShopGoods
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>产品套餐列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
    <link rel="stylesheet" href="~/Content/font.css">
    <link rel="stylesheet" href="~/Content/framemain.css">
    <link rel="stylesheet" href="~/Content/pagination.css" />
    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Scripts/common.js"></script>
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <style>
        .layui-table img {
            max-width: inherit;
        }

        .pro-img {
            border-radius: 5px;
            border: 1px solid #f2f2f2;
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    @using (Html.BeginForm("ProductList", "Goods", FormMethod.Get))
    {
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="javascript:;">首页</a>
                <a><cite>产品套餐列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        if (returnMsg.code == 200)
        {
            <div class="layui-fluid">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <div class="layui-card layui-form">
                            <div class="layui-card-header">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" class="layui-input" name="keywords" id="keywords" value="@ViewBag.Keyword" placeholder="请输入套餐编码或名称" />
                                    <input type="hidden" name="uid" id="uid" value="@ViewData["SelectUser"]" />
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="hidden" name="pageSize" id="pageSize" value="@ViewData["pageSize"]" />
                                    <input type="hidden" name="page" id="page" value="@ViewData["page"]" />
                                </div>
                                <input type="submit" value="&#xe615; 查询" class="layui-btn layui-btn-select layui-icon" />
                                <a class="layui-btn" onclick="xadmin.open('编辑商品','/Goods/ProductEdit?action=Add&id=0',800,600)"><i class="layui-icon">&#xe61f;</i>添加</a>
                                <a id="btnDelete" class="layui-btn layui-btn-danger" onclick="ExePostBack(this);"><i class="layui-icon">&#xe640;</i>删除</a>
                            </div>
                            <div class="layui-card-body ">
                                <table class="layui-table layui-form">
                                    <thead>
                                        <tr>
                                            <th width="2%">
                                                <input type="checkbox" lay-filter="checkall" id="checkalll" name="checkalll" lay-skin="primary">
                                            </th>
                                            <th>产品封面</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>标签</th>
                                            <th>市场价（￥）</th>
                                            <th>出售价（￥）</th>
                                            <th>活动价（￥）</th>
                                            <th>成本价（￥）</th>
                                            <th>销售提成（￥）</th>
                                            <th>库存数量</th>
                                            <th>是否上架</th>
                                            <th>创建日期</th>
                                            <th width="15%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @{
                                            if (ViewBag.ProductList.Count > 0)
                                            {
                                                foreach (DeliveryManage.Model.Pro_ShopGoods item in ViewBag.ProductList)
                                                {
                                                    <tr>
                                                        <td>
                                                            <input type="checkbox" name="chkid" lay-skin="primary" class="checkall" />
                                                            <input type="hidden" name="hidid" value="@item.Id" />
                                                        </td>
                                                        <td>
                                                            <a title="是否查看该套餐产品封面" href="@item.Picture" target="_blank">
                                                            <img src="@(string.IsNullOrEmpty(item.Picture) ? "/images/none.png" : item.Picture)" alt="产品封面" class="pro-img" /> </a>
                                                        </td>
                                                        <td>@item.Code</td>
                                                        <td><h3>@item.Name</h3> </td>
                                                        <td>
                                                            @{
                                                                if (item.Lable)
                                                                {
                                                                    <button type="button" class="layui-btn layui-bg-orange layui-btn-radius">促销</button>
                                                                }
                                                                else
                                                                {
                                                                    <button type="button" class="layui-btn layui-bg-blue layui-btn-radius">标准</button>
                                                                }
                                                            }
                                                        </td>
                                                        <td>@item.NormalPrice ￥</td>
                                                        <td>@item.CounterPrices ￥</td>
                                                        <td>@item.ActivityPrices ￥</td>
                                                        <td>@item.CostPrice ￥</td>
                                                        <td>@item.Commission ￥</td>
                                                        <td>@item.Stock 件</td>
                                                        <td>
                                                            <input type="checkbox" name="close" lay-skin="switch" lay-text="上架|下架" disabled="disabled" @(item.IsShow == true ? "checked" : "")>
                                                        </td>
                                                        <td>@(item.ShowDate == null?"—— ——": Convert.ToDateTime(item.ShowDate).ToLongTimeString())</td>
                                                        <td>
                                                            <div class="layui-btn-container">
                                                                <a title="修改" class="layui-btn layui-btn-xs" onclick="xadmin.open('修改','/Goods/ProductEdit?action=edit&id=@item.Id',800,600)" href="javascript:;"><i class="layui-icon">&#xe642;</i>修改</a>
                                                                <a title="是否@(item.IsShow == true ? "下架该商品" : "上架该商品")" class="layui-btn layui-btn-xs @(item.IsShow == true ? "layui-bg-blue" : "layui-bg-orange")" onclick="onIsShowProdouct(@item.Id,'@(item.IsShow == true ? "下架该商品" : "上架该商品")')" href="javascript:;"><i class="layui-icon">&#xe643;</i>@(item.IsShow == true ? "下架" : "上架")</a>
                                                                <a title="点击删除该商品" class="layui-btn layui-btn-xs layui-btn-danger" onclick="onDelProdouct(@item.Id)" href="javascript:;"><i class="layui-icon">&#xe640;</i>删除</a>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                }
                                            }
                                            else
                                            {
                                                <tr>
                                                    <td colspan="14" align="center" height="200"><img src="~/images/nodata.png" style=" width: 10%; " /><br /> 暂无相关数据</td>
                                                </tr>
                                            }
                                        }

                                    </tbody>
                                </table>
                            </div>

                            <div class="pagelist">
                                <div id="PageContent" class="default">@Html.Raw(ViewBag.PageInnerHtml)</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        }
    }

    <script type="text/javascript">
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('tbody .checkall').prop('checked', true);
            } else {
                $('tbody .checkall').prop('checked', false);
            }
            form.render('checkbox');
        });
        //切换分页大小
        form.on('select(selectpage)', function (data) {
            var data = thisdata();//搜索条件
            locations(data);
        })
    });

    //批量删除
    function ExePostBack(objId) {
        var arr = $(".checkall");
        var ids = "";
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].checked) {
                ids += arr[i].parentElement.children[2].value + ",";
            }
        }
        if (ids.length < 1) {
            layer.alert('对不起，请选中您要操作的记录！', { icon: 2, title: '提示' }, function (index) {
                layer.close();
                return false;
            });
            return false;
        }
        var msg = "删除记录后不可恢复，您确定吗？";
        if (arguments.length == 2) {
            msg = objmsg;
        }
        layer.confirm(msg, { icon: 3, title: '提示' }, function (index) {
            $.ajax({
                type: "POST",
                url: "/VoiceBot/ProccessEdit",
                data: { id: ids },
                success: function (obj) {
                    layer.alert(obj.msg, { icon: 6 }, function () {
                        if (obj.code == 200) {
                            layer.close();
                            location.reload();
                        }
                    });
                }
            })
            layer.close();
        });
        return false;
    }

    //是否上或下架架商品
    function onIsShowProdouct(id, tishi) {
        tishi = tishi + '，您确定吗？';
        layer.confirm(tishi, { icon: 3, title: '提示' }, function (index) {
            $.ajax({
                type: "POST",
                url: "/Goods/IsShowProdouct",
                data: { id: id },
                success: function (obj) {
                    layer.alert(obj.msg, { icon: 6 }, function () {
                        if (obj.code == 200) {
                            layer.close();
                            location.reload();
                        }
                    });
                }
            })
            layer.close();
        })
    }

    //删除商品
    function onDelProdouct(objId) {
        var msg = "删除该商品后不可恢复，您确定吗？";
        if (arguments.length == 2) {
            msg = objmsg;
        }
        layer.confirm(msg, { icon: 3, title: '提示' }, function (index) {
            $.ajax({
                type: "POST",
                url: "/Goods/DelProdouct",
                data: { sourseid: objId },
                success: function (obj) {
                    layer.msg(obj.msg, { icon: 6 });
                    location.reload();
                }
            })
            layer.close();
        });
        return false;
    }
    //搜索参数函数
    function thisdata()
    {
        var data = {
            pageCount: $('.txtPageCount').val(),
            pageSize: $("select[name=select_page").val(), //获取到所选的id
            keywords: $('#keywords').val(),
            uid: $('#uid').val(),
        };

        if (data.pageCount=="") {
            data.pageCount= @ViewData["page"];
        }
        return data;
    }

    //调用页面方法
    function locations(data) {
        window.location.href = '/Shop/ProductList?page=' + data.pageCount + "&pageSize=" + data.pageSize + '&keywords=' + data.keywords + '&uid=' + data.uid;
        }

      $(function () {
            //操作提示
            if (@returnMsg.code == 400) {
                layer.msg('@returnMsg.msg', { icon: 5, title: '提示' }, function (index) {
                  layer.close();
                })
            }

            //跳转页
            $("#locationPageBtn").click(function () {
                var data = thisdata();//搜索条件
                locations(data);
            });
        })
    </script>
</body>
</html>
